﻿{
    formName: "",
    formJson: {},

    setFormName: function(name) {
        this.formName = name || "form:first";
    },

    setJson: function(json) {
        this.formJson = json || {};
        return this;
    },

    ready: function() {
        new FormTool(this.formJson, this.formName).target("_blank").submit(this);
    },
    
    preSubmit: function() {
        return this.fCheck();
    },

    fTrim: function(str) {
        return str.replace(/(^\s*)|(\s*$)/g, ""); 
    },

    fCheckCookie: function() {
        var secure = document.getElementsByName("secure");
        var cookieEnabled=(navigator.cookieEnabled)? true : false;
        if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
            document.cookie="testcookie";
            cookieEnabled=(document.cookie=="testcookie")? true : false;
            document.cookie="";
        }
        if(secure.length>0){
            if(secure[0].checked && !cookieEnabled){
                return false;
            }
        }
        return true;
    },

    fCheck: function() {
        var bOk = false;
        var s = "";
        var fm = document.form;
        s = fm.style.value;

        fm.user.value = this.fTrim(fm.user.value); //Trim the input value.
        if(!this.fCheckCookie()){
            return false;
        }
        if( fm.user.value =="") {
            return false;
        }

        if( fm.password.value.length =="") {
            return false;
        }
        var remUser = fm.remUser.checked?true:false;

        var secure = fm.secure;
        var url;
        if(secure.checked){
            url = "https://reg.163.com/logins.jsp";
        }else{
            url = "http://reg.163.com/login.jsp";
        }
        url +="?type=1&product=mail126&url=http://entry.mail.126.com/cgi/ntesdoor?hid%3D10010102%26lightweight%3D1%26";
        if( fm.secure.checked )
            url += "verifycookie%3D1%26";
        url += "language%3D0%26style%3D" + s ;
        try{
            var sMailSpeed = getCookie("mailspeed");
            if(sMailSpeed){
                url += "%26webname_prefix%3D"+sMailSpeed.split("_")[0];
            }
        }catch(exp){}
        fm.action = url;
        var ati = fm.user.value.indexOf( "@"); 
        if( ati != -1 )
            fm.user.value = fm.user.value.substring(0, ati);
        if(!fm.remUser.checked){
            //setCookie('ntes_mail_noremember','true',true);
        }else{
            fm.savelogin.value = 1;
        }
        fm.username.value = fm.user.value + "@126.com";
        return true;
    }
}
